package com.ali.common;

import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;

public class ChronoUnitUtil {
    /**
     * 获取相差年
     */
    public static long getBetweenYear(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
        return ChronoUnit.YEARS.between(temporal1Inclusive, temporal2Exclusive);
    }

    /**
     * 获取相差月
     */
    public static long getBetweenMonth(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
        return ChronoUnit.MONTHS.between(temporal1Inclusive, temporal2Exclusive);
    }

    /**
     * 获取相差日
     */
    public static long getBetweenDay(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
        return ChronoUnit.DAYS.between(temporal1Inclusive, temporal2Exclusive);
    }

    /**
     * 获取相差时
     */
    public static long getBetweenHour(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
        return ChronoUnit.HOURS.between(temporal1Inclusive, temporal2Exclusive);
    }

    /**
     * 获取相差分
     */
    public static long getBetweenMinute(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
        return ChronoUnit.MINUTES.between(temporal1Inclusive, temporal2Exclusive);
    }

    /**
     * 获取相差秒
     */
    public static long getBetweenSecond(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
        return ChronoUnit.SECONDS.between(temporal1Inclusive, temporal2Exclusive);
    }
}